name: CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  GO111MODULE: on

jobs:

  build:
    name: Build
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        build: [ linux, darwin, windows ]
        include:
          - build: linux
            os: ubuntu-latest
          - build: darwin
            os: macos-latest
          - build: windows
            os: windows-latest

    steps:

    - name: Set up Go
      uses: actions/setup-go@v3
      with:
        go-version: "1.20"
      id: go

    - name: Install gox
      run: go install github.com/mitchellh/gox@latest

    - name: Check out code into the Go module directory
      uses: actions/checkout@v3

    - name: Build
      run: gox -osarch="${{ matrix.build }}/amd64" -ldflags "-s -w -X copyto/cmd.Version=v1.2.${{ github.run_number }}-dev" copyto

    - name: Test with coverage
      if: matrix.build == 'linux'
      run: go test -coverprofile=coverage.txt -coverpkg copyto/logic,copyto/logic/internal/sys,copyto/cmd -covermode=atomic copyto/...

    - name: Test
      if: matrix.build != 'linux'
      run: go test ./...

    - name: Static analysis
      uses: dominikh/staticcheck-action@v1.3.0
      with:
        version: "2022.1.3"
        install-go: true

    - name: Send coverage
      if: matrix.build == 'linux'
      run: |
        curl -Os https://uploader.codecov.io/latest/linux/codecov
        chmod +x codecov
        ./codecov -t ${{ env.CODECOV_TOKEN }}

